package openjdk.jdk8;

import java.time.*;
import java.util.Date;

public class Time {
    public static void main(String[] args) {

        System.out.println();
        System.out.println("今天的开始时间的milli表示法:");
        System.out.println("LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli(): " + LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli());
        System.out.println("LocalDateTime.of(LocalDate.now(), LocalTime.MIN).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(): " + LocalDateTime.of(LocalDate.now(), LocalTime.MIN).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());

        System.out.println();
        System.out.println("当前时间的milli表示法：");
        System.out.println("LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(): " + LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
        System.out.println("System.currentTimeMillis(): " + System.currentTimeMillis());
        System.out.println("new Date().getTime(): " + new Date().getTime());
        System.out.println("LocalDate.now() : "  + LocalDate.now());
        System.out.println("LocalDate.now().toString() : " + LocalDate.now().toString());

        System.out.println();
        System.out.println("EpochDay 显示的是距 　1970-01-01 的天数:");
        LocalDate localDate = LocalDate.of(1971,01,1);
        System.out.println(localDate.toEpochDay());
        System.out.println(localDate.toEpochSecond(LocalTime.MIN, ZoneOffset.ofHours(8)));
        System.out.println(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli());
        LocalDateTime ldt = Instant.ofEpochMilli(localDate.toEpochSecond(LocalTime.MIN, ZoneOffset.ofHours(8)) * 1000)
                .atZone(ZoneId.systemDefault())
                .toLocalDateTime();
        System.out.println(ldt);


        System.out.println();
        System.out.println("通过milliseconds来构造一个LocalDate:");
        long milliseconds = 1230134400000L;
        LocalDate date = Instant.ofEpochMilli(milliseconds).atZone(ZoneId.systemDefault()).toLocalDate();
        System.out.println("milliseconds:"+milliseconds + "  构造出的Date:" + date);
    }
}
